package com.cwt_taxi_xa;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cwt_taxi_xa.model.MessageCenter;
import com.cwt_taxi_xa.util.AppLog;
import com.cwt_taxi_xa.util.DateUtil;
import com.cwt_taxi_xa.util.ExceptionUtil;

public class MessageAdapter extends BaseAdapter{
	private static final String TAG = "MessageAdapter.";
	public Context context;
	private LayoutInflater mInflater=null;
	private List<MessageCenter> list;
	private MessageCenter obj;
	
	public MessageAdapter(Context context) {
		this.context = context;
		this.mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		if(null!=list&&list.size()>0){
			return list.size();
		}
		
		return 0;
	}
	
	public void setData(List<MessageCenter> list) {
		this.list = list;
	}
	
	@Override
	public Object getItem(int arg0) {
		return list.get(arg0);
	}
	
	public void addItems(List<MessageCenter> nlist) {
		for (int i = 0; i < nlist.size(); i++) {
			this.list.add(nlist.get(i));
		}
	}
	
	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		try {
			if(convertView == null){
				convertView = mInflater.inflate(R.layout.message_list_item,null );
			}
			 TextView text = (TextView) convertView.findViewById(R.id.message);  
			 TextView create_time = (TextView) convertView.findViewById(R.id.create_time);  
			 TextView onlyid = (TextView) convertView.findViewById(R.id.onlyid);  
			 obj = list.get(position);
			 text.setText(obj.getContent());  
			 create_time.setText(DateUtil.getShowTime(obj.getCreatetime()));  
//			 onlyid.setText(String.valueOf(obj.getId()));  
		     return convertView;  
			
		} catch (Exception e) {
			AppLog.e(ExceptionUtil.getInfo(e), e);
			e.printStackTrace();
			return null;
		}
		
	}
	

}
